package control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import Dao.UserDao;
import Dao.UserDaoimpl;
import entity.User;
import service.UserService;
import service.UserServicsImpl;

public class Getuser  extends HttpServlet{
   UserService us = new UserServicsImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("login post");
		String email = null;
		Integer typeid = null;;
		String password = null;
		for(Cookie c:req.getCookies()) {
			if(c.getName().equals("email")) {
				email = c.getValue();
			}
			if(c.getName().equals("typeid")) {
				typeid = Integer.valueOf(c.getValue());
			}
			if(c.getName().equals("password")) {
				password = c.getValue();
			}
		}
		req.setCharacterEncoding("utf-8");
		User user = null;
		try {
			user = us.getUser(email);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resp.setCharacterEncoding("utf-8");
		resp.getWriter().print(JSON.toJSON(user));
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}
}
